﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace InstrumentCheck.SQLHelper
{
    public class Helper
    {
        //connection string
        private static string CorrectItemConnString = ConfigurationManager.ConnectionStrings["ConnectString"].ToString();

        //Create SqlConnection
        public static SqlConnection GetConnection()
        {
            SqlConnection cn = new SqlConnection();
            cn.ConnectionString = CorrectItemConnString;
            return cn;
        }

        //Open Database Connection
        public static void OpenConnection(SqlConnection p_conn)
        {
            try
            {
                if (p_conn.State == ConnectionState.Closed)
                    p_conn.Open();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //Close DataBase Connection
        public static void CloseConnection(SqlConnection p_conn)
        {
            try
            {
                if (p_conn.State == ConnectionState.Open)
                {
                    p_conn.Close();
                    p_conn.Dispose();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
